<?php
/**
 * Prado Portal.
 *
 * @author Steen Rabol <steen.rabol@gmail.com>
 * @link http://www.pradoportal.dk/
 * @copyright Copyright &copy; 2006,2007,2008 Steen Rabol
 * @license http://www.pradoportal.dk
 * @version $Id: TRCTextBox.php 452 2011-01-06 16:24:38Z steen.rabol $
 *
 */

class TRCTextBox extends TWebControl implements IDataRenderer
{
    const PATH_ASSETS	= 'assets';
    const FILE_JS		= 'rounded-corners.js';

    /* We publish our worker javascript file. */
    public function onPreRender($param)
    {
        $publish	= dirname(__FILE__) . '/' . self::PATH_ASSETS;
        $url		= Prado::getApplication()->getAssetManager()->publishFilePath($publish);
        $this->getPage()->getClientScript()->registerScriptFile($url, $url . '/' . self::FILE_JS);
    }

	public function onInit()
	{
		if($this->Id === '')
		{
			throw new TInvalidDataValueException("TRCTextBox requires and ID");
		}
	}

	public function render($writer)
	{
		parent::render($writer);
	}

	protected function getTagName()
	{
		return 'div';
	}

	public function renderContents($writer)
	{
		if(($text=$this->getText()) === '')
		{
			parent::renderContents($writer);
		}
		else
		{
			$writer->write($text);
		}

		$rc			= 'rc_' . $this->getClientId();
		$script		= "$rc = new DHTMLgoodies_roundedCorners()\r\n";
		$backcolor	= ($this->BackColor !="" ? $this->BackColor : "#FF0000");
		$width		= ($this->Width !="" ? $this->Width : "10");

		//							divId,xRadius,yRadius,color,backgroundColor,padding,heightOfContent,whichCorners)
		$padding	= $this->Padding != 0 ? $this->Padding : 10;
		$height		= ($this->Height !== '' ? $this->Height : 0);
		$script		.= $rc . ".addTarget('" . $this->getClientId() . "'," . $this->XRadius . "," . $this->YRadius . ",'$backcolor','$backcolor',$padding,$height,'" . $this->Corners . "');\r\n";
		$script		.= $rc . ".init();\r\n";
		$this->getPage()->getClientScript()->registerEndScript($rc,$script);
	}

	public function getData()
	{
		return $this->getText();
	}

	public function setData($value)
	{
		$this->setText($value);
	}

	public function getText()
	{
		return $this->getViewState('Text','');
	}

	/**
	 * @param string the text value of the label
	 */
	public function setText($value)
	{
		$this->setViewState('Text',$value,'');
	}

	public function getPadding()
	{
		return $this->getViewState('Padding',10);
	}

	public function setPadding($value)
	{
		$this->setViewState('Padding',$value,10);
	}

	public function getXRadius()
	{
		return $this->getViewState('xRadius',25);
	}

	public function setXRadius($value)
	{
		$this->setViewState('xRadius',$value,25);
	}

	public function getYRadius()
	{
		return $this->getViewState('yRadius',25);
	}

	public function setYRadius($value)
	{
		$this->setViewState('yRadius',$value,25);
	}

	public function getCorners()
	{
		return $this->getViewState('Corners','');
	}

	public function setCorners($value)
	{
		$this->setViewState('Corners',$value,'');
	}
}
?>